import { ILoadMapTypeAll } from '@/common';
import { getTenantID } from '@/utils';
import { InputNumber, Select } from 'antd';
import { ColumnsRenderFun, DictionaryRenderFun, formatDecimal, getColorTextDoms } from '@/pages/PurchaseManage/Acommon';

// 排序
const getSorter = (prev: Record<string, any>, next: Record<string, any>): number => (prev > next ? 1 : -1);
/**
 * @getMaterialTableColumns
 * @description 物料弹窗表格信息
 */
const getMaterialTableColumns = (onEditTableFun): Record<string, any>[] => {
  return [
    {
      title: '物料名称',
      dataIndex: 'fullName',
      key: 'fullName',
      visible: true,
      width: 170,
      fixed: 'left',
      unDrag: false,
      sorter: (a: any, b: any) => getSorter(a?.fullName, b?.fullName),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '物料类型',
      dataIndex: 'materialTypeName',
      key: 'materialTypeName',
      visible: true,
      width: 120,
      sorter: (a: any, b: any) => getSorter(a?.materialTypeName, b?.materialTypeName),
      render: (text: string | null) => DictionaryRenderFun({ text }),
    },
    {
      title: '规格要求（参数）', // needParams[需求物料表中]  specInfo[物料表中]
      dataIndex: 'needParams',
      key: 'needParams',
      visible: true,
      width: 180,
      sorter: (a: any, b: any) => getSorter(a?.needParams, b?.needParams),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '规格型号',
      dataIndex: 'modelNum',
      key: 'modelNum',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => getSorter(a?.modelNum, b?.modelNum),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '量化单位',
      dataIndex: 'unitBusinessName',
      key: 'unitBusinessName',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => getSorter(a?.unitBusiness, b?.unitBusiness),
      render: (text: string | null) => DictionaryRenderFun({ text }),
    },
    {
      title: '参考单价（元）',
      dataIndex: 'unitPrice',
      key: 'unitPrice',
      visible: true,
      width: 200,
      sorter: (a: any, b: any) => getSorter(a?.unitPrice, b?.unitPrice),
      render: (text: string | null) => <span>{formatDecimal(text)}</span>,
    },
    {
      title: '物料简介',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      visible: true,
      width: 180,
      sorter: (a: any, b: any) => getSorter(a?.paramsInfo, b?.paramsInfo),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true, wordNum: 100 }),
    },
    // {
    //   title: '标的类别',
    //   dataIndex: 'supplyType',
    //   key: 'supplyType',
    //   width: 150,
    //   fixed: 'right',
    //   visible: true,
    //   render: (text, record) => {
    //     return (
    //       <>
    //         <Select
    //           placeholder="请选择"
    //           style={{ width: '100%' }}
    //           onSelect={(val, node) => onEditTableFun('supplyType', node, record)}
    //           value={text || undefined}
    //           options={[
    //             {
    //               value: `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}1003`,
    //               label: '材料类',
    //             },
    //             {
    //               value: `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}1004`,
    //               label: '资产类',
    //             },
    //           ]}
    //         />
    //       </>
    //     );
    //   },
    // },
    {
      title: '采购单价',
      dataIndex: 'expectPrice',
      key: 'expectPrice',
      visible: true,
      width: 150,
      fixed: 'right',
      render: (text, record, arr) => {
        return (
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <InputNumber
              value={text}
              style={{ width: '100%' }}
              placeholder="请输入"
              step="0.01"
              onChange={(value: any) => {
                onEditTableFun('expectPrice', value, record);
              }}
              min={1}
              disabled={text == 0}
            />
          </div>
        );
      },
    },
    {
      title: '采购数量',
      dataIndex: 'expectNum',
      key: 'expectNum',
      visible: true,
      width: 160,
      fixed: 'right',
      render: (text, record, arr) => {
        return (
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <InputNumber
              value={text}
              style={{ width: '100%' }}
              placeholder="请输入"
              onChange={(value: any) => {
                onEditTableFun('expectNum', value, record);
              }}
              min={1}
              // max={MaxNum}
              disabled={text == 0}
            />
            <div style={{ marginLeft: '5px' }}>{getColorTextDoms(record?.unitBusinessName)}</div>
          </div>
        );
      },
    },
  ];
};

export { getMaterialTableColumns };
